﻿using System.ComponentModel;
using System.Reflection;

namespace System
{
    public static class EnumEx
    {
        public static string ToDescription(this Enum value)
        {
            var txt = value.ToString();
            var field = value.GetType().GetField(txt);
            var attr = field.GetCustomAttribute<DescriptionAttribute>();
            if (attr != null)
            {
                return attr.Description;
            }
            return txt;
        }
    }
}